#include "Data.hpp"


using namespace aer;


Data::Data()
{
  viewer.camera = NULL;
  pScene = NULL;
}

Data::~Data()
{
  release();
}

void Data::init(Scene *pScene)
{
  // ============
  // == Viewer ==   ~~
  // ============
  aer::View view( Vector3(25.0f, 15.0f, 25.0f),
                  Vector3(0.0f, 0.0f, 0.0f),
                  Vector3(0.0f, 1.0f, 0.0f) );
  
  aer::Frustum frustum( 60.0f, 1.0f, 0.1f, 1000.0f);
  
  viewer.camera = new aer::FreeCamera( view, frustum);
  viewer.camera->setMoveCoefficient(1.0f);
  viewer.camera->setRotationCoefficient(0.01f);
  //viewer.camera->setInertiaCoefficient(0.92f);
  

  // ==========
  // == Misc ==
  // ==========  
  this->pScene = pScene;
}

void Data::resize( const int width, const int height)
{
  // Camera aspectRatio xxx
  aer::Frustum frustum = viewer.camera->getFrustum();
  frustum.setAspectRatio( width / float(height) );
  viewer.camera->setFrustum( frustum ); //
}

void Data::update()
{
  // ============
  // == Camera ==
  // ============
  viewer.camera->update();
  
  
  // ========================
  // == PostEffects params ==
  // ========================
  effectsParams.linearizationParams = viewer.camera->getFrustum().getLinearizationParams();
}

void Data::release()
{
  AER_SAFE_DELETE( viewer.camera );
}
